// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()

    //定义变量,接受页面提交的参数,获取用户创建时间
    let user_create_time = event.user_create_time;
    let user_nickname = event.user_nickname;
    let avatarUrl = event.avatarUrl;
    // console.log("aaaaa==>",user_create_time,user_nickname,avatarUrl);
    //用户身份
    let open_id = wxContext.OPENID;
    let unionid = wxContext.UNIONID;
    //小程序ID
    // let appid = wxContext.APPID

    if(wxContext){
        //返回处理结果
        return {
            code:200,
            msg:"注册成功",
            userInfo:{
                user_nickname,
                avatarUrl,
                user_create_time,
                open_id
            }
        }
    }else{
        return{
            code:-1,
            msg:"注册失败"
        }
    }

    // return {
    //     event,
    //     openid: wxContext.OPENID,
    //     appid: wxContext.APPID,
    //     unionid: wxContext.UNIONID,
    // }
}